<template>
	<view>
		<view class="tap">
			<view class="tabOne" :class="flag==0?'onTab':''" @click="tabOne">
				<view class="txt">文件详情</view>
				<view class="strip"></view>
			</view>
			<view class="tabTwo" :class="flag==1?'onTab':''" @click="tabTwo">
				<view class="txt">相似文件</view>
				<view class="strip"></view>
			</view>
		</view>
		<view class="box" v-if="flag==0">
			<view class="title">{{arr.title}}</view>
			<view class="tag">
				<view class="tag-y" v-for="(item,index) in str" :key="index">
					{{item}}
				</view>
			</view>
			<view class="writing">
				<view class="txt">
					<u-parse :content="arr.introduction"></u-parse>
				</view>
			</view>
			<view class="hr_line"></view>
			<view class="card" @click="onPdf">
				<view class="left">
					<image src="https://img.wilmer.com.cn/admin/2024/3-22/pdf.png" alt="" />
				</view>
				<view class="right">{{arr.title}}</view>
			</view>
		</view>
		<view class="box_list" v-if="flag==1">
			<view v-for="(item,index) in list" :key="index" @click="onBox(item)">
				<view class="box-z">
					<view class="title">{{item.title}}</view>
					<view class="tag">
						<view class="tag-y" v-for="(nav,j) in item.tags.split(',')" :key="j">
							{{nav}}
						</view>
					</view>
					<view class="card" style="margin: 30rpx 0;">
						<view class="left">
							<image src="https://img.wilmer.com.cn/admin/2024/3-22/pdf.png" alt="" />
						</view>
						<view class="right">{{item.title}}</view>
					</view>
				</view>
				<view class="hr"></view>
			</view>
		</view>
		<view style="height: 80rpx;width: 1rpx;"></view>
	</view>
</template>

<script>
	import {
		DetailDocument,
		Getdocument
	} from '@/common/api/homePage.js'
	export default {
		data() {
			return {
				flag: 0, // 选中变色
				list: [], // 文件列表
				arr: {}, // 文件详情
				str: [], // 标签
			}
		},
		onLoad(options) {
			if (options.id) {
				this.GetDetail(options.id)
			}
		},
		methods: {
			tabOne() {
				this.flag = 0
			},
			tabTwo() {
				this.flag = 1
				this.GetList()
			},
			GetDetail(id) {
				uni.showLoading({
					title: '加载中'
				});
				DetailDocument(id).then(res => {
					setTimeout(() => {
						uni.hideLoading();
					}, 500)
					this.arr = res.data.data
					if (res.data.data.tags) {
						this.str = res.data.data.tags.split(',')
					}
				})
			},
			GetList() {
				uni.showLoading({
					title: '加载中'
				});
				Getdocument().then(res => {
					setTimeout(() => {
						uni.hideLoading();
					}, 500)
					this.list = res.data.rows
				})
			},
			onPdf() {
				uni.downloadFile({
					url: this.arr.file.split(',')[0],
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							fileType: 'pdf',
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
							}
						});
					}
				})
			},
			onBox(item) {
				this.flag = 0
				this.GetDetail(item.id)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tap {
		margin-bottom: 40rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;

		.tabOne {
			.txt {
				font-size: 14px;
				font-weight: 500;
			}

			.strip {
				margin-top: 10rpx;
			}
		}

		.tabTwo {
			.txt {
				font-size: 14px;
				font-weight: 500;
			}

			.strip {
				margin-top: 10rpx;
			}
		}

		.onTab {
			.txt {
				color: #00d000;
			}

			.strip {
				width: 36rpx;
				height: 4rpx;
				background-color: #00d000;
				margin: 10rpx auto 0;
			}
		}
	}

	.card {
		background-color: #f8f8f8;
		border-radius: 14rpx;
		padding: 32rpx;
		display: flex;

		.left {
			image {
				width: 48rpx;
				height: 52rpx;
			}
		}

		.right {
			font-size: 14px;
			font-weight: 400;
			margin-left: 14rpx;
			color: #666666;
		}
	}

	.box {
		width: 686rpx;
		margin: 40rpx auto 0;
		box-shadow: 0 0 5px 3px rgba(0, 0, 0, 0.1);
		border-radius: 14rpx;
		padding: 40rpx 20rpx 40rpx;

		.title {
			font-size: 14px;
			font-weight: 500;
			margin-bottom: 20rpx;
		}

		.tag {
			display: flex;
			margin-bottom: 46rpx;

			.tag-y {
				font-size: 14px;
				font-weight: 400;
				color: #40C040;
				background-color: #EFFFF6;
				border-radius: 12rpx;
				padding: 12rpx 14rpx;
				margin-right: 20rpx;
			}
		}

		.hr_line {
			width: 636rpx;
			height: 2px;
			background-color: #f8f8f8;
			margin: 72rpx auto;
		}

	}

	.box_list {
		.box-z {
			width: 686rpx;
			margin: 0 auto;

			.title {
				font-size: 14px;
				font-weight: 500;
				margin-bottom: 20rpx;
			}

			.tag {
				display: flex;

				.tag-y {
					font-size: 14px;
					font-weight: 400;
					color: #40C040;
					background-color: #EFFFF6;
					border-radius: 12rpx;
					padding: 12rpx 14rpx;
					margin-right: 20rpx;
				}
			}
		}

		.hr {
			width: 100vw;
			height: 4rpx;
			background-color: #f8f8f8;
			margin: 20rpx 0;
		}
	}
</style>